<template>
  <div class="home">
    <!-- 顶部导航 -->
    <van-nav-bar class="my-nav-bar" title="首页" fixed placeholder />
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in cars" :key="item.bannerId">
        <img class="swipe-img" :src="item.pic" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!-- 区域标题 -->
    <div class="section-title">
      <span class="line"> </span>
      编辑推荐
    </div>
    <!-- 歌单 -->
    <div class="music-list">
      <div class="items" v-for="item in per" :key="item.id">
        <!-- @click="toplay(item.id)" -->
        <div class="content">
          <img :src="item.picUrl" alt="" />
          <p>{{ item.name }}</p>
        </div>
      </div>
    </div>

    <!-- 区域标题 -->
    <div class="section-title">
      <span class="line"> </span>
      最新音乐
    </div>
    <!-- 列表 -->
    <div
      class="song-list"
      v-for="item in newSongs"
      :key="item.id"
      @click="toplay(item.id)"
    >
      <van-cell
        :title="
          item.song.name +
            (item.song.alias.length === 0 ? '' : ` + (${item.song.alias[0]})`)
        "
        size="large"
        :label="item.song.artists[0].name"
      >
        <template #right-icon>
          <van-icon name="play-circle-o" class="play-icon" />
        </template>
      </van-cell>
    </div>
  </div>
</template>

<script>
import { carousel, personalized, newSong } from '../api/index'
export default {
  created () {
    carousel({ type: 1 }).then(res => {
      // console.log(res)
      this.cars = res.data.banners
    })
    personalized({ limit: 6 }).then(res => {
      // console.log(res)
      this.per = res.data.result
    })
    newSong({ limit: 10 }).then(res => {
      // console.log(res)
      this.newSongs = res.data.result
    })
  },
  name: 'Home',
  data () {
    return {
      cars: [],
      per: [],
      newSongs: []
    }
  },
  methods: {
    toplay (id) {
      // console.log(id)
      this.$router.push({ path: '/play', query: { id } })
    }
  }
}
</script>
<style lang="less">
// 轮播图
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
.home {
  // padding-top: 46px;
}
.section-title {
  height: 50px;
  position: relative;
  background: #fcfcfd;
  border-bottom: 1px solid #e6e6e6;
  line-height: 50px;
  color: gray;
  padding-left: 10px;
  .line {
    width: 4px;
    background-color: #d43c33;
    height: 20px;
    left: 0;
    top: 15px;
    position: absolute;
  }
}
.swipe-img {
  width: 100%;
}
.music-list {
  display: flex;
  flex-wrap: wrap;
  .items {
    box-sizing: border-box;
    width: 33.333%;
    padding: 0 2px;
    margin-bottom: 10px;
    img {
      display: block;
      width: 100%;
    }
    p {
      padding: 0;
      margin: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      padding: 2px;
      font-size: 14px;
      color: gray;
    }
  }
}
.song-list .play-icon {
  font-size: 30px;
  color: gray;
}
.song-list {
  .van-cell__title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
